package com.wangtao.firstapp.activity;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.wangtao.firstapp.R;

import java.util.Calendar;

/**
 * 个人页面   设置   编辑兴趣   跳转到此页面
 * Created by lanouhn on 16/9/19.
 */
public class MyInterestConfigActivity extends AppCompatActivity {
    private ImageView iv_back_titlebar_myinterestconfig;// 标题栏返回按钮
    private TextView datepicker;// 点击选择生日
    private Button btn_next;// 下一步按钮

    // final Calendar c = Calendar.getInstance();
    // int mYear = c.get(Calendar.YEAR);
    int mYear = 1990;
    // int mMonth = c.get(Calendar.MONTH);
    int mMonth = 1;
    // int mDay = c.get(Calendar.DAY_OF_MONTH);
    int mDay = 1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myinterestconfig);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        iv_back_titlebar_myinterestconfig = (ImageView) findViewById(R.id.iv_back_titlebar_myinterestconfig);// 标题栏返回按钮
        datepicker = (TextView) findViewById(R.id.datepicker);// 点击选择生日
        btn_next = (Button) findViewById(R.id.btn_next);// 下一步
    }

    private void initData() {

    }

    private void initEvent() {
        // 标题栏返回按钮
        iv_back_titlebar_myinterestconfig.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        // 生日选择器
        datepicker.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        mYear = year;
                        mMonth = monthOfYear;
                        mDay = dayOfMonth;
                        updateDate();
                    }
                };
                DatePickerDialog dpd = new DatePickerDialog(MyInterestConfigActivity.this, listener, mYear, mMonth - 1, mDay);
                dpd.show();
            }
        });
        // 下一步
        btn_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_chooseinterest = new Intent(MyInterestConfigActivity.this, ChooseInterestActivity.class);
                startActivity(intent_chooseinterest);
                finish();
            }
        });
    }

    private void updateDate() {
        //更新EditText控件日期 小于10加0
        datepicker.setText(new StringBuilder().append(mYear).append("-")
                .append((mMonth + 1) < 10 ? "0" + (mMonth + 1) : (mMonth + 1))
                .append("-")
                .append((mDay < 10) ? "0" + mDay : mDay));
        //datepicker.setText(mYear + "-" + mMonth + "-" + mDay);
    }
}
